<?php
    
    namespace addons\zpwxsys\model;
    

    use think\Db;
    
    class Sysmsg extends BaseModel
    {
        
        protected $name = 'zpwxsys_sysmsg';
        
        public static function getTotal($map)
        {
            
            $count = self::where($map)->count();
            return $count;
            
        }
        
        
        public function getSysmsgByWhere($map, $Nowpage, $limits, $od)
        {
            $newslist = $this->where($map)->page($Nowpage, $limits)->order($od)->select();
            if ($newslist) {
                foreach ($newslist as $k => $v) {
                    $newslist[$k]['createtime'] = date('Y-m-d', $v['createtime']);
                }
                
            }
            
            
            return $newslist;
            
        }
        
        
        public static function getAllByuid($map)
        {
            
            $list = self::where($map)->order('createtime DESC')->select();
            
            
            return $list;
            
            
        }
        
        
        public function insertSysmsg($param)
        {
            
            Db::startTrans();// 启动事务
            try {
                $this->allowField(true)->save($param);
                Db::commit();// 提交事务
                $data = array('status' => 0, 'msg' => '创建成功!');
            } catch (\Exception $e) {
                Db::rollback();// 回滚事务
                
                $data = array('status' => 1, 'msg' => '提交失败');
            }
            
            
            return json_encode($data);
            
        }
        
        public function updateSysmsg($param)
        {
            Db::startTrans();// 启动事务
            try {
                $this->allowField(true)->save($param, ['uid' => $param['uid']]);
                Db::commit();// 提交事务
                $data = array('status' => 0);
            } catch (\Exception $e) {
                Db::rollback();// 回滚事务
                $data = array('status' => 1);
            }
            
            return json_encode($data);
        }
        
        
    }
